<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
    <script src="https://cdn.jsdelivr.net/npm/vue@2.5.16/dist/vue.js"></script>
    <script src="https://unpkg.com/axios/dist/axios.min.js"></script>
</head>
<body>
<div id="app">
    <todo>
        <todo-title slot="todo-title" :title="title"></todo-title>
        <todo-items slot="todo-items" v-for="(item,index) in itemValue" :item="item" :index="index" @remove="removeItem(index)"></todo-items>
    </todo>
</div>
</body>
<script>
    Vue.component("todo", {
        template: '<div>\
                        <slot name="todo-title"></slot>\
                            <ul>\
                                <slot name="todo-items"></slot>\
                            </ul>\
                   </div>'
    })
    Vue.component("todo-title",{
        props:['title'],
        template: '<div>{{title}}</div>'
    })
    Vue.component("todo-items",{
        props:['item','index'],
        template:'<li>{{item}}--{{index}}<button @click="remove">删除</button></li>',
        methods:{
            remove:function (index) {
                this.$emit('remove',index);
            }
        }
    })
    var vm = new Vue({
        el: "#app",
        data:{
            title:"cai列表",
            itemValue:["Java","Linux","前端"]
        },
        methods:{
            removeItem:function (index) {
                console.log("删除了:"+this.itemValue[index]);
                this.itemValue.splice(index,1);
            }
        }
    })
</script>
</html>